package com.lwh.Test;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.lwh.DTO.GroupDiagDTO;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author wanhua.li
 * @version 1.0
 * @description:泰州中医病组判断
 * @date 2023/1/12 14:59
 */
public class GroupDiagTest {
    public static void main(String[] args) {
        String fileName = "D:\\政策包\\床日sql\\111.xlsx" ;
        EasyExcel.read(fileName, GroupDiagDTO.class,new AnalysisEventListener<GroupDiagDTO>() {

            @Override
            public void invoke(GroupDiagDTO groupDiagDTO, AnalysisContext context) {
                //分组编码
                String oldGroup = groupDiagDTO.getGroupCode();
                String[] splitGroup = oldGroup.split(",");
                List<String> finalGroup = new ArrayList<>();
                List<String> newGroup = Arrays.asList(splitGroup);
                String last = newGroup.get(newGroup.size()-1);
                for (String diag:newGroup){
                    if (diag.equals(last)){
                        diag = "'"+diag+"'";
                    }else{
                        diag = "'"+diag+"',";
                    }
                    finalGroup.add(diag);
                }
                finalGroup.add(0,"(分组编码 in(");
                finalGroup.add(finalGroup.size(),")");
                finalGroup.forEach(System.out::print);
                System.out.print(" and ");
                //诊断编码
                String oldDiag = groupDiagDTO.getDiagCode();
                String[] split = oldDiag.split(";");
                List<String> finalDiag = new ArrayList<>();
                List<String> newDiag = Arrays.asList(split);
                String lastDiag = newDiag.get(newDiag.size() - 1);
                for (String diag:newDiag){
                    if (diag.equals(lastDiag)){
                        diag = "'"+diag+"'";
                    }else{
                        diag = "'"+diag+"',";
                    }
                    finalDiag.add(diag);
                }
                finalDiag.add(0,"主诊断 in(");
                finalDiag.add(finalDiag.size(),")");
                finalDiag.forEach(System.out::print);
                System.out.println(") or ");
                System.out.println();
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext context) {

            }
        }).sheet().doRead();
    }
}
